Skip to content

fix(open-responses): preserve reasoning in tool loops - #18546

Closed
gr2m wants to merge 1 commit into
mainfrom
codex/fix-open-responses-reasoning-replay
Closed

gr2m wants to merge 1 commit into
mainfrom
codex/fix-open-responses-reasoning-replay

Conversation

@gr2m

@gr2m gr2m commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Background

@ai-sdk/open-responses parsed provider reasoning items into assistant reasoning parts, but silently dropped those parts when the assistant output was replayed in a subsequent tool-loop request.

The live-provider investigation in #18512 captured the missing reasoning item, but DeepSeek accepted that request when its provider-issued tool call ID was retained. The provider-free reproduction in #18514 isolated the serialization defect independently of that provider behavior.

Summary

  • Serialize assistant reasoning parts as Open Responses reasoning items with reasoning_text content.
  • Keep replayed reasoning immediately before its function call and tool result.
  • Narrow the request type for reasoning content.
  • Add converter regression coverage and a provider-free end-to-end reproduction.
  • Add a patch changeset for @ai-sdk/open-responses.

End-to-End Verification

Ran the provider-free two-step reproduction:

pnpm -C examples/ai-functions exec tsx src/reproduction/issue-18511-open-responses-reasoning-round-trip.ts

It completed successfully with the expected second-request ordering:

message, reasoning, function_call, function_call_output

Verification

  • pnpm --filter @ai-sdk/open-responses test
  • pnpm --filter @ai-sdk/open-responses build
  • pnpm --filter @example/ai-functions type-check
  • pnpm check
  • pnpm type-check:full

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #18511
Fixes #18513

Closes #18512
Closes #18514
Closes #18515

Co-authored by Co-authored-by: Astro-Han 255364436+Astro-Han@users.noreply.github.com

@gr2m gr2m closed this in #18515 Aug 11, 2026
pull Bot pushed a commit to gaylonalfano/ai that referenced this pull request Aug 11, 2026
…t in tool loops (vercel#18515)

## Background

The published @ai-sdk/open-responses package lost assistant reasoning
when its generated content was replayed in a tool loop, sending zero
reasoning items after parsing one.

## Root Cause

The assistant-content switch in convertToOpenResponsesInput handled only
text and tool-call parts, so parsed reasoning parts fell through without
serialization; the offline reproduction confirmed one reasoning part was
read and zero were sent.

## Summary

Assistant reasoning parts are now serialized as Open Responses reasoning
items with reasoning_text content. The request type was tightened
accordingly, and a patch changeset was added.

## Testing

Added regression coverage asserting that assistant reasoning becomes a
correctly shaped reasoning input item.

## End-to-end Validation

- `pnpm -C packages/open-responses build`; `pnpm -C
examples/ai-functions exec tsx
src/reproduction/issue-18513-open-responses-reasoning-round-trip.ts` —
the offline round trip sent one reasoning item instead of zero and
exited successfully.

## Related Issues

Fixes vercel#18513

Closes vercel#18514

Closes vercel#18546

---------

Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com>
Co-authored-by: Astro-Han <255364436+Astro-Han@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant